'''
@Project ：my_python_project 
@File    ：作业2.py
@IDE     ：PyCharm 
@Author  ：xionglinhui
@Date    ：2024/7/3 下午3:45 
'''
'''
二.去重
　　 1. 有列表l=['a','b',1,'a','a']，列表元素均为可hash类型，去重，得到新列表,且新列表无需保持列表原来的顺序
'''
# l1=['a','b',1,'a','a']
# l1_set = set(l1)
# # print(l_set)
# l1_lst = list(l1_set)
# print(l1_lst)

'''2.在上题的基础上，保存列表原来的顺序'''
# l2=['a','b',1,'a','a', 'b']
# new_l = []
# seen = set()
# for x in l2:
#     if x not in seen:
#         new_l.append(x)
#         seen.add(x)
#
# print(f'new_l为：{new_l}')
# print(f'seen为：{seen}')


'''3.去除文件中重复的行，肯定要保持文件内容的顺序不变'''

'''4.有如下列表，列表元素为不可hash类型，去重，得到新列表，且新列表一定要保持列表原来的顺序

l3=[
    {'name':'egon','age':18,'sex':'male'},
    {'name':'alex','age':73,'sex':'male'},
    {'name':'egon','age':20,'sex':'female'},
    {'name':'egon','age':18,'sex':'male'},
    {'name':'egon','age':18,'sex':'male'},
]
'''
l3=[
    {'name':'egon','age':18,'sex':'male'},
    {'name':'alex','age':73,'sex':'male'},
    {'name':'egon','age':20,'sex':'female'},
    {'name':'egon','age':18,'sex':'male'},
    {'name':'egon','age':18,'sex':'male'},
]

set_new = set()
list_new = []

for j in l3:
    if j not in list_new:
        list_new.append(j)

print(list_new)




